package Vista;


import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JTextField;

import javax.swing.WindowConstants;
import javax.swing.SwingUtilities;

import Controlador.Sistema;
import java.awt.BorderLayout;
import java.awt.FlowLayout;


/**
* This code was edited or generated using CloudGarden's Jigloo
* SWT/Swing GUI Builder, which is free for non-commercial
* use. If Jigloo is being used commercially (ie, by a corporation,
* company or business for any purpose whatever) then you
* should purchase a license for each developer using Jigloo.
* Please visit www.cloudgarden.com for details.
* Use of Jigloo implies acceptance of these licensing terms.
* A COMMERCIAL LICENSE HAS NOT BEEN PURCHASED FOR
* THIS MACHINE, SO JIGLOO OR THIS CODE CANNOT BE USED
* LEGALLY FOR ANY CORPORATE OR COMMERCIAL PURPOSE.
*/
public class ViewAltaCliente extends javax.swing.JFrame 
{
	
	private JLabel jLabel2;
	private JLabel jLabel3;
	private JLabel jLabel4;
	private JTextField nombre;
	private JLabel jLabel5;
	private JLabel jLabel6;
	private JTextField jTemail;
	private JLabel jLMensaje;
	private JTextField apellido;
	private JButton cancelar;
	private JButton ok;
	private JTextField dni;
	private JTextField telefono;
	private JTextField domicilio;
	private JLabel jLabel1;	
	public static ViewAltaCliente instancia;

	private static final long serialVersionUID = 1L;

	/**
	* Auto-generated main method to display this JFrame
	*/
	public static void main(String[] args) {
		SwingUtilities.invokeLater(new Runnable() {
			public void run() {
				ViewAltaCliente inst = new ViewAltaCliente();
				inst.setLocationRelativeTo(null);
				inst.setVisible(true);
				
			}
		});
	}
	
	private ViewAltaCliente() {
		super();
		initGUI();
	}
	
	public static ViewAltaCliente getInstancia() 
	{
		if (instancia== null)
			instancia = new ViewAltaCliente();
		return instancia;
	}
		
	
	public ViewAltaCliente(MenuPrincipal mnu) {
		super();
		initGUI();
		mnu.dispose();
	}
	private void initGUI() {
		try {
			setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
			getContentPane().setLayout(null);
			this.setTitle("Alta Cliente");

			{
				jLabel1 = new JLabel();
				getContentPane().add(jLabel1);
				jLabel1.setText("Nombre :");
				jLabel1.setBounds(21, 36, 64, 14);
			}
			{
				jLabel2 = new JLabel();
				getContentPane().add(jLabel2);
				jLabel2.setText("Domicilio :");
				jLabel2.setBounds(21, 107, 64, 16);
			}
			{
				jLabel3 = new JLabel();
				getContentPane().add(jLabel3);
				jLabel3.setText("Telefono :");
				jLabel3.setBounds(21, 145, 64, 14);
			}
			{
				jLabel4 = new JLabel();
				getContentPane().add(jLabel4);
				jLabel4.setText("DNI :");
				jLabel4.setBounds(21, 174, 64, 18);
			}
			{
				nombre = new JTextField();
				getContentPane().add(nombre);
				nombre.setBounds(97, 33, 219, 21);
			}
			{
				domicilio = new JTextField();
				getContentPane().add(domicilio);
				domicilio.setBounds(97, 104, 219, 22);
			}
			{
				telefono = new JTextField();
				getContentPane().add(telefono);
				telefono.setBounds(97, 138, 219, 21);
			}
			{
				dni = new JTextField();
				getContentPane().add(dni);
				dni.setBounds(97, 171, 219, 21);
			}
			{
				ok = new JButton();
				getContentPane().add(ok);
				ok.setText("Aceptar");
				ok.setBounds(33, 300, 105, 21);
				ok.addActionListener(new ActionListener() {
					public void actionPerformed(ActionEvent evt) 
					{
						boolean a = false;
						a = Sistema.getInstancia().altaCliente(dni.getText() , apellido.getText(), nombre.getText(), domicilio.getText(), Integer.parseInt(telefono.getText()), jTemail.getText(), 1);
						if (a) 
						{
						limpiarPantalla();
						jLMensaje.setText("CLIENTE CARGADO EXITOSAMENTE");
						}
						else
						{
						limpiarPantalla();
						jLMensaje.setText("CLIENTE EXISTENTE");
						}
					}
				});
			}
			{
				cancelar = new JButton();
				getContentPane().add(cancelar);
				cancelar.setText("Cancelar");
				cancelar.setBounds(240, 300, 114, 21);
				cancelar.addActionListener(new ActionListener() {
					public void actionPerformed(ActionEvent evt)
					{
						limpiarPantalla();
					}
				});
			}
			{
				jLabel5 = new JLabel();
				getContentPane().add(jLabel5);
				jLabel5.setText("Apellido:");
				jLabel5.setBounds(21, 70, 64, 15);
			}
			{
				apellido = new JTextField();
				getContentPane().add(apellido);
				getContentPane().add(getJLMensaje());
				getContentPane().add(getJTextField1());
				getContentPane().add(getJLabel6());
				apellido.setText("");
				apellido.setBounds(97, 66, 219, 22);
			}
			pack();
			this.setSize(427, 382);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
		private void limpiarPantalla()
		{
			nombre.setText("");
			apellido.setText("");
			domicilio.setText("");
			telefono.setText("");
			dni.setText("");
			jLMensaje.setText("");
		}
		
		private JLabel getJLMensaje() {
			if(jLMensaje == null) {
				jLMensaje = new JLabel();
				jLMensaje.setBounds(33, 260, 321, 22);
			}
			return jLMensaje;
		}
		
		private JTextField getJTextField1() {
			if(jTemail == null) {
				jTemail = new JTextField();
				jTemail.setText("");
				jTemail.setBounds(97, 214, 219, 21);
			}
			return jTemail;
		}
		
		private JLabel getJLabel6() {
			if(jLabel6 == null) {
				jLabel6 = new JLabel();
				jLabel6.setText("EMAIL");
				jLabel6.setBounds(21, 217, 64, 18);
			}
			return jLabel6;
		}
}
